package com.minisoft.pool;

import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;


public class ExcelMD5Encryption {
    public static void main(String[] args) {
        try {
//            FileInputStream excelFile = new FileInputStream(new File("d:/temp/_身份证是43开头及成交地址包含湖南及指定前缀__202310071106.xlsx"));
            ExcelWriter writer = ExcelUtil.getWriter("d:/temp/md5加密7.25.xlsx");
            for (Sheet sheet : writer.getSheets()) {
                for (Row row : sheet) {
                    Cell cellA = row.getCell(0); // Assuming phone numbers are in column A
                    if (cellA != null) {
                        String phoneNumber = cellA.getStringCellValue();
                        String encryptedPhoneNumber = DigestUtil.md5Hex(phoneNumber);

                        Cell cellB = row.createCell(1, CellType.STRING); // Create or get cell in column B
                        cellB.setCellValue(encryptedPhoneNumber);
                    }
                }
            }
            writer.close();
            System.out.println("MD5加密完成并保存到B列！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
